<?php

class MediaController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $dir = 'files';
        $handle = opendir($dir);
        $dirs = array();
        while($file = readdir($handle)):
            if($file != '.' && $file != '..'):
             $dirs[] = $file;    
            endif;
        endwhile;
        $this->view->dirs = $dirs;
    }

    public function musicAction()
    {
        $dir = 'files/music';
        $handle = opendir($dir);
        $mp3 = array();
        while($file = readdir($handle)):
            if($file != '.' && $file != '..'):
             $mp3[] = $file;    
            endif;
        endwhile;
        $this->view->mp3 = $mp3;
        $this->view->dir = $dir;
        
                    $request = $this->getRequest();
                    $form = new Application_Model_Form_Upload_Media();
                           $request = $this->getRequest();
                    if ($request->isPost()) {
                            if ( $form->isValid( $request->getPost() ) ) {
                                $adapter = $form->image->getTransferAdapter();
                                foreach ($adapter->getFileInfo() as $file) {
                                $ext = preg_split("[/\\.]", $file['name']);
                                $newName = $ext[count($ext)-1];
                                $adapter->addFilter('Rename', realpath(dirname('.')).
                                    DIRECTORY_SEPARATOR.
                                    'files/music'.
                                    DIRECTORY_SEPARATOR.
                                    $newName);
                                $adapter->receive($file['name']);
                                $this->_redirect('/media/music');
                                }
                            }
                            }
                     $this->view->form = $form;
                      $this->view->title = 'Music';
    }

    public function picturesAction()
    {
        $dir    =    "files/pictures";
$pic = array();
if ($handle = opendir($dir)) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") :
            if (is_dir($dir."/".$entry) === true){
                echo "DIRECTORY: ".$entry."\n";
            }else{
                echo "FILE: ".$entry."\n";
                                $pic[] = $entry;
                
            }
      endif;
    }
    closedir($handle);
}
  
        $this->view->dir = $dir;
         $this->view->pic = $pic;
        $this->view->title = 'Pictures';
    }

    public function addAction()
    {

    }


}









